package cn.jsp.reflect;

import java.lang.reflect.Field;

public class ReflectDemo {
    public static void main(String[] args) throws Exception {
        //new
        Class<SimpleObj> clazz= SimpleObj.class;
        Object obj= clazz.getDeclaredConstructor().newInstance();
        //set
        Field field=clazz.getDeclaredField("age");
        field.setAccessible(true);//设置可以访问私有变量，在第一次访问前设置
        System.out.println(field.get(obj));
        field.set(obj,21);
        System.out.println(obj);

    }
}
